package com.rocket.activity;

import android.app.Activity;
import android.view.KeyEvent;
import android.widget.Toast;

import com.rocket.util.DialogUtil;
import com.rocket.util.MenuUtil;

public abstract class MenuActivity extends Activity {

	int			contentId;

	Toast		toast;

	MenuUtil	mMenu;
	DialogUtil	mDialog;

	@Override
	public void setContentView(int layoutResID) {
		contentId = layoutResID;
		super.setContentView(layoutResID);
	}

	protected void showToast(String text) {
		if (toast == null) {
			toast = Toast.makeText(MenuActivity.this.getApplicationContext(), text, Toast.LENGTH_LONG);
			toast.show();
		} else {
			toast.cancel();
			toast.setText(text);
			toast.show();
		}
	}

	/**
	 * 修改键盘的菜单单击事件
	 */
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_MENU) {
			if (mMenu == null) {
				openMenu();
			} else {
				mMenu.show();
			}
			return true;
		} else {
			return super.onKeyDown(keyCode, event);
		}
	}

	protected abstract void openMenu();
}
